var numsetp= 0;
function getfetch(){
var penname = document.getElementById('penname').value;
var ersaid = document.getElementById('ersaid').value;
var userid = sessionStorage.getItem("user");
if(penname === '' || ersaid === '' || penname.length >10 || ersaid.length >50){
    Qmsg.error('不能为空或内容过长');
    numsetp--;
    return false;
}
fetch('ht/newsq.php',{
    method: 'POST',
            headers: {
                'Content-Type': 'application/json; charset=utf-8'
            },
            body: JSON.stringify({
                penname: penname,
                sentence: ersaid,
                userid: userid
            })
        }).then(response => response.json())
        .then(data => {
        if(data.code === 200){
            Qmsg.success(data.msg);
            document.getElementById('nextstep').click();
        }else{
            Qmsg.error(data.msg);
            numsetp--;
            return false;
        }
    })
}
document.getElementById('nextstep').addEventListener('click', function() {
    numsetp++;
    if(numsetp===2){
        if(!getfetch()){
            return false;
        }
    }else if(numsetp===3){
        document.getElementById('nextstep').style.display = 'none';
    }
    var steps = document.querySelectorAll('.steps > li');
    var activeIndex = Array.from(steps).findIndex(el => el.classList.contains('active'));
    var currentStep = document.querySelector('.steps .active');
    var nextStepId = currentStep.getAttribute('id').replace('step-', '');
    var nextStepIdwb = parseInt(nextStepId) + 1;
    var nextStepContentId = 'step-' + nextStepIdwb.toString() + '-content';
    var allStepContents = document.querySelectorAll('.step-content-item');
    allStepContents.forEach(function(content) {
        content.classList.remove('active');
        content.classList.add('hidden');
    });
    var nextStepContent = document.getElementById(nextStepContentId);
    nextStepContent.classList.remove('hidden');
    nextStepContent.classList.add('active');
    if (activeIndex < steps.length - 1) {
        steps[activeIndex].classList.remove('active');
        steps[activeIndex + 1].classList.add('active');
        updateStepContent(activeIndex + 1);
    }
});
window.addEventListener('DOMContentLoaded', function() {
    var firstStepContent = document.getElementById('step-1-content');
    firstStepContent.classList.add('active');
});
function updateStepContent(index) {
    var stepContent = document.querySelector('.step-content');
    var steps = document.querySelectorAll('.steps > li');
}
function qdtjform(){
    alert("qdtjform");
}